import interceptor from 'rest/interceptor';

export default interceptor({
  init: function (config) {
    config.code = config.code || 400;
    return config;
  },
  request: function handleRequest(request, config) {
    var headers, name, token;

    console.log('auth.handleRequest:::::::::;', request);

    headers = request.headers || (request.headers = {});
    name = 'Authorization';
    token = window.sessionStorage.getItem('token') || '';

    if (token && !headers[name]) {
      headers[name] = 'Bearer ' + token;
    }

    return request;
  }
});
